package com.example.note.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(
    entities = {DiaryEntity.class, ReminderEntity.class},
    version = 1,
    exportSchema = false
)
public abstract class NoteDatabase extends RoomDatabase {
    
    private static final String DATABASE_NAME = "note_database";
    private static volatile NoteDatabase INSTANCE;
    
    public abstract DiaryDao diaryDao();
    public abstract ReminderDao reminderDao();
    
    public static NoteDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            synchronized (NoteDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(
                        context.getApplicationContext(),
                        NoteDatabase.class,
                        DATABASE_NAME
                    ).build();
                }
            }
        }
        return INSTANCE;
    }
    
    public static void destroyInstance() {
        INSTANCE = null;
    }
}